package com.sjksy.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sjksy.demo.domain.TravelContract;
import com.sjksy.demo.domain.TravelRoute;
import com.sjksy.demo.dto.guide.GuideInfoDto;
import com.sjksy.demo.mapper.GuideMapper;
import com.sjksy.demo.mapper.TravelRouteMapper;
import com.sjksy.demo.msmapper.travel_contract.TravelContractMsMapper;
import com.sjksy.demo.service.TravelContractService;
import com.sjksy.demo.mapper.TravelContractMapper;
import com.sjksy.demo.vo.travel_contract.TravelContractInsertVo;
import com.sjksy.demo.vo.travel_contract.TravelContractShowVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author guyueyuan
* @description 针对表【travel_contract】的数据库操作Service实现
* @createDate 2024-12-11 15:37:02
*/
@Service
public class TravelContractServiceImpl extends ServiceImpl<TravelContractMapper, TravelContract>
    implements TravelContractService{

    @Resource
    TravelContractMapper travelContractMapper;
    @Resource
    TravelRouteMapper travelRouteMapper;
    @Resource
    GuideMapper guideMapper;
    @Resource
    TravelContractMsMapper travelContractMsMapper;

    @Override
    public boolean insertTravelContract(TravelContractInsertVo travelContractInsertVo) {
        return travelContractMapper.insert(travelContractMsMapper.insertVoToTravelContract(travelContractInsertVo))>=1;
    }

    @Override
    public List<TravelContractShowVo> getAllTravelContract() {
        List<TravelContract> travelContracts = travelContractMapper.selectList(null);
        List<TravelContractShowVo> travelContractShowVoList=new ArrayList<>();
        travelContracts.forEach(travelContract -> {
            TravelRoute travelRoute = travelRouteMapper.selectById(travelContract.getRouteId());
            GuideInfoDto guideInfoDto=guideMapper.getEmployeeInfoByGuideId(travelContract.getGuideId());
            TravelContractShowVo travelContractShowVo = travelContractMsMapper.dtoToTravelContractShowVo(travelRoute, guideInfoDto, travelContract);
            travelContractShowVoList.add(travelContractShowVo);
        });
        return travelContractShowVoList;
    }

    @Override
    public boolean updateTravelContract(TravelContractInsertVo travelContractInsertVo) {
        return travelContractMapper.updateById(travelContractMsMapper.insertVoToTravelContract(travelContractInsertVo))>=1;
    }
}




